package com.heiyanqiang.service.impl;

import com.heiyanqiang.dao.RoleDao;
import com.heiyanqiang.domain.Permission;
import com.heiyanqiang.domain.Role;
import com.heiyanqiang.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleDao roleDao;
    //查询所有权限
    @Override
    public List<Role> findAll() throws Exception {
        return roleDao.findAll();
    }
    //添加权限
    @Override
    public void save(Role role) {
        roleDao.save(role);
    }

    //根据roleId查询
    @Override
    public Role findById(Integer roleId) {
        return roleDao.findById(roleId);
    }

    //根据roleId查询permission
    @Override
    public List<Permission> findOtherPermissions(Integer roleId) {
        return roleDao.findOtherPermissions(roleId) ;
    }
    //添加权限到角色
    @Override
    public void addPermissionToRole(Integer roleId, Integer[] permissionIds) {
        for (Integer permissionId : permissionIds) {
            roleDao.addPermissionToRole(roleId,permissionId);
        }


    }
}
